/**
 * @program: FindFileDemo
 * @author: Ding Houwen
 * @create: 2019-08-01 13:28
 **/

package com.example.findfiledemo.service.impl;

import com.example.findfiledemo.entiy.FileEntiy;
import com.example.findfiledemo.mapper.FileMapper;
import com.example.findfiledemo.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Iterator;
import java.util.List;

@Service
public class FileServiceImpl implements FileService {

    @Autowired
    private FileMapper fileMapper;

    @Override
    public List<FileEntiy> FindFileByName(String name) {
        return fileMapper.FindFileByName(name);
    }

    @Override
    public List<FileEntiy> FindFileByDetails(String name) {
        return fileMapper.FindFileByDetails(name);
    }

    @Override
    public List<FileEntiy> FindFile(String name) {

        //获取两种搜索方方法的结果
        List<FileEntiy> filelistA = FindFileByName(name);
        List<FileEntiy> filelistB = FindFileByDetails(name);
        //对结果进行去重处理
        for (FileEntiy fileEntiy : filelistA) {
            Iterator<FileEntiy> iterator = filelistB.iterator();
            while (iterator.hasNext()) {
                FileEntiy next = iterator.next();
                if (next.getFileid() == ( fileEntiy.getFileid() )) {
                    iterator.remove();
                }
            }
        }
        //合并去重后的结果
        filelistA.addAll(filelistB);
        return filelistA;
    }

    @Override
    public String FindDetailsById(int fileid) {
        return fileMapper.FindDetailsById(fileid);
    }
}

